package com.fdb.efp.esb.service.impl.zx;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.fdb.efp.esb.common.constant.ESBTradeNoConstance;
import com.fdb.basic.framework.core.exception.ESBException;
import com.fdb.efp.esb.service.bo.req.NLMHitQueryReports;
import com.fdb.efp.esb.service.bo.resp.zx.NLMHitQueryResponseReports;
import com.fdb.efp.esb.service.impl.esb.BaseEsbService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service;

import java.util.Optional;
import java.util.function.Function;

/**
 * 需求编号:2020D0220
 * 名单系统40120008查询服务
 *
 * @author F嘉阳
 * @date 2020/3/2 14:13
 */
@Service("zx11008Service")
@DependsOn("ZXConfig")
public class ZX11008ServiceImpl extends BaseEsbService<NLMHitQueryReports, NLMHitQueryResponseReports> {

    private static Logger logger = LoggerFactory.getLogger(ZX11008ServiceImpl.class);

    /**
     * 对接口返回结果进行处理，并返回包装后的结果
     *
     * @param reqBean
     * @param resBean
     * @return
     * @throws Exception
     */
    @Override
    protected NLMHitQueryResponseReports postProcess(NLMHitQueryReports reqBean, NLMHitQueryResponseReports resBean) throws Exception {
        Optional.
                ofNullable(resBean).
                map(i -> i.getBlklistCustFlg()).
                orElseThrow(() -> new ESBException("名单系统查询返回为空！"));
        logger.debug("名单系统查询进行后续处理，请求参数: " + reqBean + ", 返回结果： " + resBean);
        return resBean;
    }

    @Override
    protected String tradeNo() {
        return ESBTradeNoConstance.ZX11008;
    }

    @Override
    protected String scene() {
        return "10";
    }

    @Override
    protected Function<String, NLMHitQueryResponseReports> converter() {
        return i -> JSONObject.parseObject(i, new TypeReference<NLMHitQueryResponseReports>() {});
    }
}
